<?php
echo<<<STOP
<link href="http://{$_SERVER['SERVER_NAME']}/css/grid.css" type=text/css rel=stylesheet>
<link href="http://{$_SERVER['SERVER_NAME']}/modules/news/css/news.css" type=text/css rel=stylesheet>

<script type="text/javascript" src="http://{$_SERVER['SERVER_NAME']}/modules/general/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://{$_SERVER['SERVER_NAME']}/modules/image_rotator/image_rotator.js"></script>
<script type="text/javascript" src="http://{$_SERVER['SERVER_NAME']}/modules/image_scroller/image_scroller.js"></script>
<script type="text/javascript" src="http://{$_SERVER['SERVER_NAME']}/modules/news/news.js"></script>
<script  type="text/javascript">
var m = 6000;
var _image_rotator = new image_rotator("",m); 
var _text_rotator = new image_rotator("text_rotator",m,330,330);  
var _image_scroller = new image_scroller("", m, 330, 50 , 60); 
_news = new news();
</script>
STOP;
?>
<?php 
if(!isset($_SESSION)) @session_start();

$folder = opendir("{$_SERVER["DOCUMENT_ROOT"]}/modules/news/banners");
$pic_types = array("jpg", "jpeg", "gif", "png");
$index = array();
$text_data = array();
while ($file = readdir ($folder)) {
    if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types)) {
        array_push($index,$file);
    }
}

closedir($folder);
if (! isset($_SESSION["username"])) {
shuffle($index);
?>


<?php


echo "<script language=javascript> var text_data = {";
for ($i=0; $i<count($index); $i++) {
    $text_file = substr ($index[$i],0,strpos($index[$i],".")) . ".html";
    $text ="/modules/news/banners/" . $text_file;
    echo "\"{$index[$i]}\" : \"{$text}\"";
    if ($i < count($index)-1) echo ",";
}  

echo "};</script>";




echo <<<STOP
<div id="news_area" newsHold=0 class="advert_area" >
        <div class="news h_3_25">
            <div id=news_left_box class="h_4" >
            <div id=rotator style="display:none"><ul>
STOP;
$w=330;
for ($i=0;$i<count($index);$i++) {
    $l=$w*$i;
    echo "<li><img  class=news_main_image  src=\"/modules/news/banners/{$index[$i]}\" />";
}
echo <<<STOP
            </ul></div>
            </div>
            <div id=news_right_box>
                <div id=news_scoll_box>
                    <div id=news_text_box><div id=text_rotator style="display:none"><ul>                   
STOP;
for ($i=0;$i<count($index);$i++) { 
	?> <li><div  style=" "  class="news_main_text"><?php 
	$text_file = substr ($index[$i],0,strpos($index[$i],".")) . ".html";
        $text ="{$_SERVER["DOCUMENT_ROOT"]}/modules/news/banners/" . $text_file;
	include $text;
	?></div>
	<?php } ?>
</ul></div></div>
                    <div id=news_scollbar>
                    <!--  input type=image id=news_scroll_left onclick="javascript:scroll_left ();" class="news_arrows gutter"  src="/images/home_arrow_left.png"-->
                    <div id=news_scroll_center><div id=scroller style="display: none"><ul><?php
for ($i=0;$i<count($index);$i++) {  ?>                         
<li><img 
                    	style="cursor:pointer"  
                    	class=news_scroll_img
                    	
                        onclick="_image_rotator.goTo(<?php echo $i; ?>);_text_rotator.goTo(<?php echo $i; ?>);_image_scroller.stop();"
                    	
                    	src="/modules/news/banners/<?php echo $index[$i]; ?>" 
                    />               
<?php }
                    ?></ul></div></div>
                    </div>
                    </div>
                </div>
            </div>
            
        </div>
<?php } else {
   ?>
        <script type="text/javascript" src="/modules/htmlView/htmlView.js"></script>
        <?php

    echo "<script type=\"text/javascript\">";
    //echo "var pic_index = {};";
    foreach ($index as $key => $data) {
        echo "_news.edit.pic_index[{$key}] =  \"{$data}\";";
    }
    echo "</script>";
   echo <<<STOP

<div id="news_area" newsHold=0 class="advert_area">
        <div class="news h_3">
            <div id=news_left_box class="h_4"  onclick="_news.edit.image_selection.initialize();">A
            </div>
            <div id=news_right_box contenteditable 
                onkeyup="_news.edit.text_updated=true;"
                onclick="_news.edit.initialize();"
            >
 
            </div>
            <div id=news_scollbar>
            <button onclick="_news.edit.next();_htmlView.html2text();">Next &rarr;</button>
            <button onclick="_news.edit.save();_htmlView.html2text();">Save</button>
            </div>
                
       
        </div>
        <div id=image_update_area></div>
</div>
<script type="text/javascript">
_news.edit.load(0);
$("#news_right_box").change(function () {_news.edit.text_updated=true;});
_htmlView = new htmlView ("news_right_box",165,630,function () {_news.edit.text_updated=true});
</script>
STOP;
    
    
}
?>

